package labox.innovation.gameserver.model.actor.instance;

import labox.innovation.gameserver.model.FuzeWorld;
import labox.innovation.gameserver.model.actor.L2Character;
import labox.innovation.gameserver.templates.chars.NpcTemplate;

/**
 * 怪物仆从实例对象 分组管理的怪物,由 有一种叫RaidBoss的主怪 和若干被叫做仆从的努力组成.
 * 
 * @version $Revision: 1.20.4.6 $ $Date: 2005/04/06 16:13:39 $
 */
public class L2MinionInstance extends FuzeMonsterInstance {

	/**
	 * 此仆从听命的主怪对象
	 */
	private FuzeMonsterInstance _master;

	/**
	 * Constructor of L2MinionInstance (use L2Character and L2NpcInstance constructor).<BR>
	 * <BR>
	 * 
	 * <B><U> Actions</U> :</B><BR>
	 * <BR>
	 * <li>Call the L2Character constructor to set the _template of the L2MinionInstance (copy skills from template to object and link _calculators to NPC_STD_CALCULATOR)</li> <li>Set the name of the L2MinionInstance</li> <li>Create a RandomAnimation Task that will be launched after the calculated delay if the server allow it</li><BR>
	 * <BR>
	 * 
	 * @param objectId
	 *            Identifier of the object to initialized
	 * @param NpcTemplate
	 *            Template to apply to the NPC
	 */
	public L2MinionInstance(long objectId, NpcTemplate template) {
		super(objectId, template);
	}

	/**
	 * 仆从类怪物，每次都是重新分配内存，所以死亡一定要离开时间，以免内存泄露
	 */
	@Override
	public void onDecay() {
		super.onDecay();
		FuzeWorld.getInstance().exitWorld(this);
	}

	/**
	 * Return the master of this L2MinionInstance.<BR>
	 * <BR>
	 */
	public FuzeMonsterInstance getLeader() {
		return _master;
	}

	@Override
	public void onSpawn() {
		if (getLeader() != null) {
			if (getLeader().isRaid()) {//如果头领是团队型的
				setIsRaidMinion(true);//设置自己是团队型中的仆从
			}
			//通知主怪仆从已经出生了
			getLeader().notifyMinionSpawned(this);
		}
		super.onSpawn();
	}

	/**
	 * 设置此仆从听命的主怪.<BR>
	 * <BR>
	 * 
	 * @param leader
	 *            The L2Character that leads this L2MinionInstance
	 * 
	 */
	public void setLeader(FuzeMonsterInstance leader) {
		_master = leader;
	}

	/**
	 * Manages the doDie event for this L2MinionInstance.<BR>
	 * <BR>
	 * 
	 * @param killer
	 *            The L2Character that killed this L2MinionInstance.<BR>
	 * <BR>
	 */
	@Override
	public boolean doDie(L2Character killer) {
		if (!super.doDie(killer))
			return false;
		if (getLeader() != null)
			getLeader().notifyMinionDied(this);
		return true;
	}
}
